package ooday03;

public class PolymorphicDemo {
    public static void main(String[] args) {
        /*Master master = new Master();
        Dog dog = new Dog("小黑","黑",2);
        Chick chick = new Chick("小花","花",1);
        Fish fish = new Fish("小金","金",3);
        master.feed(dog);
        master.feed(chick);
        master.feed(fish);

         */
        Animal[]animals = new Animal[4];
        animals[0] = new Dog("小黑","黑",3);
        animals[1] = new Chick("小黄","黄",2);
        animals[2] = new Fish("小蓝","蓝",2);
        animals[3] = new Dog("大黄","黄",5);
        for (int i = 0 ; i < animals.length ; i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }

            if(animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
            if(animals[i] instanceof Swim){
                Swim s = (Swim) animals[i];
                s.swim();
            }
        }


        /*Animal o = new Dog("小黑","黑",3);
        Dog d = (Dog) o;
        System.out.println(o instanceof Dog);
        System.out.println(o instanceof Swim);
        System.out.println(o instanceof Fish);
        if (o instanceof Fish){
            Fish f = (Fish) o;
        }else {
            System.out.println("o不是Fish类型");
        }

         */

    }
}
